package ch.zhaw.cctd.domain.prototype;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * Representiert ein TowerTyp und dessen Einstellungen im XML Config File
 * @author Rolf Koch
 * @author Benjamin Felder
 */
public class TowerPrototype extends Prototype implements Serializable {
	
	private static final long serialVersionUID = -8983342894181786794L;

	public static class TowerEffectPrototype implements Serializable {
		private static final long serialVersionUID = -7108108278741770404L;
		public TowerEffectPrototype(String type, String value) {
			this.type = type;
			this.value = new Integer(value);
		}
		public final String type;
		public final Integer value;
	}
	
	public TowerPrototype(Map<String,String> data, List<TowerUpgradePrototype> upgrades) {
		super(data);
		this.upgrades = upgrades;
		this.effects = this.getDataList("effects.effect", 
				new DataListCallback<TowerEffectPrototype>() {
					@Override
					public TowerEffectPrototype call(String... values) {
						return new TowerEffectPrototype(values[0], values[1]);
					}
			}, "type", "#text");
	}
	
	private List<TowerUpgradePrototype> upgrades;
	private List<TowerEffectPrototype> effects;
	
	public String getTitle() {
		return this.getValue("title");
	}
	
	public String getImagePath() {
		return this.getValue("image.path");
	}
	
	public int getDamage() {
		return this.getIntegerValueWith0("damage.#text");
	}
	
	public int getCost() {
		return this.getIntegerValueWith0("cost");
	}
	
	public List<String> getAbilities() {
		return this.getListValue("abilities.ability.name");
	}
	
	public List<TowerEffectPrototype> getEffects() {
		return this.effects;
	}
	
	public List<TowerUpgradePrototype> getUpgrades() {
		return this.upgrades;
	}

	public int getSpeed() {
		return this.getIntegerValueWith0("speed.#text");
	}

	public int getRange() {
		return this.getIntegerValueWith0("range.#text");
	}

	public int getSize() {
		return this.getIntegerValueWith0("size.#text");
	}
	
	public int getShotSpeed() {
		return this.getIntegerValueWith0("shot.speed.#text");
	}
	
	public int getShotXSize() {
		return this.getIntegerValueWith0("shot.xsize.#text");
	}
	
	public int getShotYSize() {
		return this.getIntegerValueWith0("shot.ysize.#text");
	}
	
	public String getShotImagePath() {
		return this.getValue("shot.image.path");
	}
	
}
